home *** CD-ROM | disk | FTP | other *** search
Perl Script | 1995-12-23 | 2.4 KB | 96 lines | [TEXT/R*ch] |
- #!/usr/bin/perl
-
- # Filter and concatenate FTP.pl
- # This script appends lines from one file to another, ignoring those lines that match a filter string
- # The output is a list of FTP URLs
- #
- # 12/22/95 Version 1.0
- # This script is free, public domain, no strings attached.
- # Igor Livshits <igorl@uiuc.edu>
-
-
- $openToAppend= ">> ";
- $macPathDelimiter= ":";
- $argumentCounter= 0;
- $newLineDelimiter= "\n";
- $omitFilterTag= "#-" . $newLineDelimiter;
- $keepFilterTag= "#+" . $newLineDelimiter;
- $true= (1 == 1);
- $false= (1 == 0);
-
-
- # Read in the arguments passed to us from the AppleScript agent
- #
- $workingDirectory= $ARGV[$argumentCounter++] . $macPathDelimiter;
- $dataDirectory= $ARGV[$argumentCounter++] . $macPathDelimiter;
- $linesAddedFile= $ARGV[$argumentCounter++];
- $filtersFile= $ARGV[$argumentCounter++];
- $newFilesFile= $ARGV[$argumentCounter++];
- $urlFile= $ARGV[$argumentCounter++];
-
-
- # Read the URL
- #
- open(urlFile, $dataDirectory . $urlFile) || die "Cannot open $urlFile: $!";
- $rootURL= <urlFile>;
- if ($rootURL =~ /$newLineDelimiter$/) { chop ($rootURL); }
- close(urlFile);
-
-
- # Classify the filters
- #
- open(filtersFile, $dataDirectory . $filtersFile) || die "Cannot open $filtersFile: $!";
- $tagLine= <filtersFile>;
- if ($tagLine eq $keepFilterTag)
- {
- $omitMatches= $false; # filter matches are kept, the rest is dropped
- }
- else # default condition
- {
- $omitMatches= $true; # filter matches are dropped, the rest is kept
- if ($tagLine ne $omitFilterTag)
- {
- seek(filtersFile, 0, 0); # restart at the beginning of the file as the first line was not a tag
- }
- }
-
-
- # Read the filters
- #
- @filters= (); # clear the array
- while (<filtersFile>)
- {
- if (/$newLineDelimiter$/) { chop; }
- if ($_) { push(@filters, $_); } # only add non-blank filters
- }
- close(filtersFile);
-
-
- # Set up input and output files
- #
- open(linesAddedFile, $dataDirectory . $linesAddedFile) || die "Cannot open $linesAddedFile: $!";
- open(newFilesFile, $openToAppend . $workingDirectory . $newFilesFile) || die "Cannot open $newFilesFile: $!";
-
-
- # Filter and add valid lines
- #
- while($aLine= <linesAddedFile>)
- {
- $match= $false;
- foreach $filter (@filters)
- {
- if ($aLine =~ /$filter/)
- { # we have a match
- $match= $true;
- last;
- }
- }
- print (newFilesFile ($rootURL . $aLine)) if ($omitMatches != $match);
- }
-
-
- # Clean up
- #
- close(linesAddedFile);
- close(newFilesFile);
-